<!DOCTYPE html>
<html>
<head> 
<#assign base=request.getContextPath()/>
<title>教学班信息</title>

<!--  
<script src="http://cdn.static.runoob.com/libs/jquery/1.10.2/jquery.min.js"></script>
-->
<link type="text/css" href="${base}/css/style.css" rel="stylesheet"/>
<script type="text/javascript" src="${base}/js/func.js"></script>
<script type="text/javascript" src="${base}/js/md5.js"></script> 
<script type="text/javascript" src="${base}/js/jquery-3.2.1.js"></script> 
<link rel="stylesheet" href="//apps.bdimg.com/libs/jqueryui/1.10.4/css/jquery-ui.min.css">
<script src="//apps.bdimg.com/libs/jquery/1.10.2/jquery.min.js "></script>
<script src="//apps.bdimg.com/libs/jqueryui/1.10.4/jquery-ui.min.js "></script>
<link rel="stylesheet" href="jqueryui/style.css">

</head>
<body>
<style>

</style>
<script>
function openDialog(){
 $( "#dialog" ).dialog( "open" );
}
</script>
<script>
		  $(function() {
		  <!-- 新建/修改的对话框 -->>
		    $( "#dialog" ).dialog(
		    {
		      autoOpen: false,
		      show: {
		        effect: "scale",
		        duration: 1000
		      		},
		      hide: {
		        effect: "explode",
		        duration: 1000
		     		 }
		     
		    });
		    <!-- 修改密码的对话框 -->
		     $( "#dialog2" ).dialog(
		    {
		      autoOpen: false,
		      show: {
		        effect: "blind",
		        duration: 1000
		      		},
		      hide: {
		        effect: "explode",
		        duration: 1000
		     		 }
		    });
		    $( ".opener2" ).click(function() {
		      $( "#dialog2" ).dialog( "open" );
		    });
		  });
</script>
<script>
     function is_submit(value) {
        var form1 = $("#form1");
        if (value == 1) {                    
            form1.action = "/classes/update";
             $("#form1").attr("action",form1.action);
            form1.submit();
        }
        if (value == 2) {
            form1.action = "/classes/insert";
            $("#form1").attr("action", form1.action);
            form1.submit();
        }
        }
</script>
<script>
    function show(){
       var obj = document.getElementById('dialog').getElementsByTagName("select");
       for(var i=0;i<4;i++){
         for(var j=0;j<obj[i].length;j++){
           if(obj[i].options[j].style.display)
           obj[i].options[j].style.display='';
          }
       }
    }
</script>
<script>

	function edit(flag,id,semester,cname,tname,tnumber){
		 
		 var obj = document.getElementById('dialog').getElementsByTagName("select");
		 var sec = document.getElementById('dialog').getElementsByTagName("INPUT");
		 var a=[semester,cname,tname,tnumber];
		 if(flag == 1){
		   sec[0].value=id;
		   for(var i=0;i<a.length;i=i+2){
		      for(var j=1;j<obj[i].length;j++){
		      if(obj[i].options[j].value==semester||obj[i].options[j].value==cname||obj[i].options[j].value==tname||obj[i].options[j].value==tnumber){
		        obj[i].options[j].selected = true; 
		        break;
		        }
		      }
             
             obj[i+1].options[0] = new Option(a[i+1],a[i+1]);
             obj[i+1].options[0].selected = true; 
           }
           document.getElementById("add").style.visibility="hidden";
           document.getElementById("change").style.visibility="visible";
         }
          else{
           for(var i=0;i<a.length;i++){
             obj[i].options[0].text = "--请选择--";
             document.getElementById("change").style.visibility="hidden";
             document.getElementById("add").style.visibility="visible";
                 }
           }
           openDialog();
	}
</script>


<script type="text/javascript">

 function protect(){
 
     var password_input = document.getElementById("Password");
     var password_md5 = document.getElementById("teacherPassword_md5");

     password_md5.value =  hex_md5(password_input.value);
     alert(password_md5)
     return true;
     
 }
</script>

<script type="text/javascript">
   <!-- 去除第一级下拉框重复选项 -->
   window.onload = function() {
   var eles=document.getElementsByClassName("del");
   for(var i=0;i<eles.length;i++){
   var opts = eles[i].options;

   var obj = new Object(), index = 0;

   while (index < opts.length) {

   if (opts[index].text in obj) opts[index] = null;

    else {

    obj[opts[index].text] = opts[index].text;

    index++;

   }

 }
     obj = null;
     }
   }
  
</script>
<script>
		  	courseNames = new Object();
		  	
		  	<#list courselist as cl>
		  		courseNames['${cl.semester}']=new Array();
		  	</#list>
		  	<#list courselist as cl>
		  	    var count = courseNames['${cl.semester}'].push('${cl.courseName}');
		  	</#list>
		  	
			function set_courseName(semester, courseName)
			{
			    var cov,clv;
			    var i, ii;
			    clv=semester.value;
			    if(clv=='0') return;
			    if(typeof(courseNames[clv])=='undefined') return;
			    <!--去除第二级下拉框选项  -->
			     $("#search").find("option:selected").text(""); 
			     $("#search").empty();
			    for(i=0; i<courseNames[clv].length; i++)
			    {
			        
			       ii=i;
			       courseName.options[ii] = new Option();
			       courseName.options[ii].text = courseNames[clv][i];
			       courseName.options[ii].value = courseNames[clv][i];
			    }
			  }
			   
</script>
<script>
           teachersNumbers= new Object();
           <#list teacherslist as te>
		  	    teachersNumbers['${te.teacherName}']=new Array();
		  	</#list>
		  	<#list teacherslist as te>
		  	    var count = teachersNumbers['${te.teacherName}'].push('${te.teacherNumber}');
		  	</#list>
		  	 function set_teacherNumber(teacherName, teacherNumber)
			{
			    var cov,clv;
			    var i, ii;
			    clv=teacherName.value;
			    if(clv=='0') return;
			    if(typeof(teachersNumbers[clv])=='undefined') return;
			     $("#search3").find("option:selected").text(""); 
			     $("#search3").empty();
			    for(i=0; i<teachersNumbers[clv].length; i++)
			    {
			        
			        ii=i;
			       teacherNumber.options[ii] = new Option();
			       teacherNumber.options[ii].text = teachersNumbers[clv][i];
			       teacherNumber.options[ii].value = teachersNumbers[clv][i];
			       
			    }
			}
</script>

<h1 style="text-align:center;font-family:arial;color:block;letter-spacing:2px;"><font size="50">小学生答题测试系统</font></h1>
	<p style="text-align:center;word-spacing:5px">
	<font size="6">
    <a href="/introduce.html">首页</a>&nbsp;
    <a href="/classes.html">教学班</a>&nbsp;&nbsp;
    <a href="/student.html">学生</a>&nbsp;&nbsp;
    <a href="/teacher.html">老师</a>&nbsp;&nbsp;
    <a href="/course.html">课程</a>&nbsp;&nbsp;
    <a href="/question.html">题库</a>&nbsp;&nbsp;
    <a href="/exam.html">测验</a>&nbsp;&nbsp;
    <a href="/loginUser.html">登录</a>&nbsp;&nbsp;
    <a href="/logout.html">退出</a>&nbsp;&nbsp;
    </font>
    </p>
 <p  style = "text-align:right;">
<input class="dv_btn"  type="button" value="修改密码 " ></input>
 </p>   
 <p  style = "text-align:left;">
<input class="dv_btn"  type="button" value="新建" onclick="edit(2,'2','2','2','2','2');"></input>
 </p> 
 
<div style="border-style:solid; border-color:#98bf21;width:400; height:150">
<table width=700 height=150 align="center">
  <tr>
    
    <th>课程编号</th>
    <th>课程名字</th>
    <th>老师工号</th>
    <th>老师姓名</th>
    <th>其他功能</th>
  </tr>

  <#list classeslist as co>
  <tr align="center">
  <td>${co.courseNumber}</td>
  <td>${co.courseName}</td>
  <td>${co.teacherNumber}</td>
  <td>${co.teacherName}</td>

  <td>
  <a href="/classes/delete?id=${co.classId}">
   <button class="dv_btn"  >删除</button>
  </a>
  <input  class="dv_btn"  type="button" value="修改" onclick="edit(1,${co.classId},'${co.semester}','${co.courseName}','${co.teacherName}','${co.teacherNumber}');"/>
  </td>  
  </tr>
  </#list>
</table>
</div>
<div class="dv_title" id="dialog"  title="课程信息">
    <form id="form1" method ="post"  action="">
         学期：<select class="del" id="select_id" name="semester" style="width:100px" onChange="set_courseName(this,this.form.courseName)"> 
         <#list courselist as cl>
         <option value="0">--请选择--</option>
		    <option value="${cl.semester}">${cl.semester}</option>
		 </#list>
       </select><br></br>
       课程名称：<select id="search" name="courseName" style="width:100px">
			<option value="0">--请选择--</option>
		</select><br></br> 
	老师姓名：<select class="del" id="id2" name="teacherName" style="width:100px" onChange="set_teacherNumber(this,this.form.teacherNumber)">
         <#list teacherslist as te>
           <option value="0">--请选择--</option> 
		    <option value="${te.teacherName}">${te.teacherName}</option>
		 </#list>
          </select><br></br>
       老师工号：<select id="search3" name="teacherNumber" style="width:100px">
		<option value="0">--请选择--</option>	
		</select><br></br>  
		<input type="hidden" name="classId",id="classId"></input>
		<input class="dialog_btn" id="change" type="button"  value="修改" onclick="is_submit(1)"></input>
        <input  class="dialog_btn" id="add" type="button"  value="新建" onclick="is_submit(2)" ></input>
	</form>
</div>
 
<div id="dialog2" title="修改密码">
			<form id="form2" method ="post"  action="/classes/update">
			老师工号：<input type="text" id="teacherNumber" name="teacherNumber"><br>
                      新密码:<input type="text" id="Password" name="Password" ><br>      
                  <input type="hidden" id="teacherPassword_md5" name="teacherPassword">
		  	      <input type="submit" value ="确定" onclick="protect();"></input>
		  	</form>
</div>
</body>
</html>
